#!/bin/sh

record_dir="/home/zte-ips-interface/GBS/gbs/sms/ZTEMediaServer/www/record/"
snap_dir="/home/zte-ips-interface/GBS/gbs/sms/ZTEMediaServer/www/snap/"

while true
do
    procnum=`ps -ef | grep "MediaServer -d" | grep -v grep | wc -l`
    if [ $procnum -eq 0 ]; then
        echo "no mediaserver"
        sudo /home/zte-ips-interface/GBS/gbs/sms/ZTEMediaServer/MediaServer -d >/dev/null&
    fi

    find ${record_dir} -mtime +7 -type f | xargs rm -rf {}
    find ${record_dir} -type d -empty | xargs rm -rf {}
    find ${snap_dir} -mtime +7 -type f | xargs rm -rf {}
    find ${snap_dir} -type d -empty | xargs rm -rf {}

    sleep 10
done
